//
//  CalculateViewController.m
//  MarryMe
//
//  Created by lanou3g on 16/1/7.
//  Copyright © 2016年 revocher. All rights reserved.
//

#import "CalculateViewController.h"
#import "CalculateTableViewCell.h"
#import "FunScrollVIew.h"
#define UISCREENWIDTH [UIScreen mainScreen].bounds.size.width//广告的宽度
@interface CalculateViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>
{
    
    //循环滚动的周期时间
    NSTimer * _moveTime;
    //用于确定滚动式由人导致的还是计时器到了,系统帮我们滚动的,YES,则为系统滚动,NO则为客户滚动(ps.在客户端中客户滚动一个广告后,这个广告的计时器要归0并重新计时)
    BOOL _isTimeUp;
}
@property (strong, nonatomic) IBOutlet UIView *headerView;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)FunScrollVIew *scorllView;
@property(nonatomic,strong)NSArray *array;
@property (nonatomic,strong)NSArray *key;
@property (nonatomic,strong)NSArray *data;
@end

@implementation CalculateViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.scorllView=[[FunScrollVIew alloc]initWithFrame:CGRectMake(0, 66, UISCREENWIDTH, 50)];
    self.scorllView.imageNameArray=@[@"banner1",@"banner2",@"banner3",@"banner4"];
    //设置PageControlS的样式
    self.scorllView.PageControlShowStyle= UIPageControlShowStyleCenter;
    //设置其他点的颜色
    self.scorllView.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
    //设置当前点的颜色
    self.scorllView.pageControl.currentPageIndicatorTintColor = [UIColor purpleColor];
    [self.headerView addSubview: self.scorllView];
  //  [self scrollViewDid];
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [customLab setTextColor:[UIColor redColor]];
    [customLab setText:@"预算结果"];
    customLab.font = [UIFont boldSystemFontOfSize:17];
    self.navigationItem.titleView = customLab;

    UIBarButtonItem *buttonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonItem:)];
    self.navigationItem.leftBarButtonItem=buttonItem;
    //注册
     [self.tableView registerNib:[UINib nibWithNibName:@"CalculateTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CalculateTableViewCell"];
    [self getArray];
    self.picLbel.text=[NSString stringWithFormat:@"%@元",self.pice];
  
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.key.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.array[section] count];
}
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
  
    return self.key[section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
      NSString *str =self.array[indexPath.section][indexPath.row];
      NSString *pricstr =self.data[indexPath.section][indexPath.row];
    CalculateTableViewCell *cell= [ tableView dequeueReusableCellWithIdentifier:@"CalculateTableViewCell"];
    cell.nameLabel.text=str;
    cell.priceLabel.text=pricstr;
    return cell;
}

-(void)getArray{
    NSArray *array=[[NSArray alloc]initWithObjects:@"婚宴预算",@"婚纱&礼服",@"婚戒",@"摄影&摄像",@"乐队&司仪", nil];
    NSArray *arr=[[NSArray alloc]initWithObjects:@"捧花&花艺",@"婚礼蛋糕",@"喜糖&回礼",@"酒水",@"婚礼卡片",@"其他(婚车)", nil];
    self.array=@[array,arr];
    self.key=@[@"预定备婚",@"选备物品"];
    
  int a = [self.priceStr intValue];
  int b = [self.number intValue];
    NSString *mz=[NSString stringWithFormat:@"%d",a*1/2/b];
    NSString *zk=[NSString stringWithFormat:@"%d",a*5/10];
    if (mz.length>3) {
        NSMutableString *s=[[NSMutableString alloc]initWithString:mz];
        [s insertString:@"," atIndex:[mz length]-3];
        mz=s;
    }
    if (zk.length>3) {
        NSMutableString *st=[[NSMutableString alloc]initWithString:zk];
        [st insertString:@"," atIndex:[zk length]-3];
        zk=st;
    }
    NSString *hy=[NSString stringWithFormat:@"%@元/桌x%@桌=%@",mz,self.number,zk];
    NSString * hs=[ NSString stringWithFormat:@"%d",a*1/10];
    NSString *hj=[NSString stringWithFormat:@"%d",a*1/10];
    NSString *sy=[NSString stringWithFormat:@"%d",a*6/100];
    NSString *yd=[NSString stringWithFormat:@"%d",a*3/100];
   
    
    NSString *ph=[NSString stringWithFormat:@"%d",a*3/100];
    NSString *dg=[NSString stringWithFormat:@"%d",a*1/100];
    NSString *xh=[NSString stringWithFormat:@"%d",a*4/100];
    NSString *xs=[NSString stringWithFormat:@"%d",a*6/100];
    NSString *hk=[NSString stringWithFormat:@"%d",a*2/100];
    NSString *qt=[NSString stringWithFormat:@"%d",a*3/100];
 
    NSMutableArray *dataAs=[NSMutableArray arrayWithObjects:hy,hs,hj,sy,yd, nil];
    NSMutableArray *arra=[NSMutableArray array];
    for (int i=0; i<dataAs.count ; i++) {
        if ([dataAs[i] length]>3&&i>0) {
            NSMutableString *stre=[[NSMutableString alloc]initWithString:dataAs[i]];
            [stre insertString:@"," atIndex:[dataAs[i] length]-3];
            dataAs[i]=stre;
        }
        [arra addObject:dataAs[i]];
    }

    
    
    
    
    NSMutableArray *dataA=[NSMutableArray arrayWithObjects:ph,dg,xh,xs,hk,qt, nil];
    NSMutableArray *dataGet=[NSMutableArray array];
    for (int i=0; i<dataA.count ; i++) {
        if ([dataA[i] length]>3) {
            NSMutableString *streee=[[NSMutableString alloc]initWithString:dataA[i]];
     [streee insertString:@"," atIndex:[dataA[i] length]-3];
            dataA[i]=streee;
        }
        [dataGet addObject:dataA[i]];
    }
    
    
    self.data=@[arra,dataGet];
}




-(void)buttonItem:(UIBarButtonItem*)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    }



@end
